package day08_stream_file_charset.com.itheima.d1_stream;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Test1_Stream {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("赵六");
        list.add("田七");
        list.add("张无忌");
        list.add("肘子若");
        list.add("赵敏");
        list.add("张强");
        list.add("张三丰");


        ArrayList<String> newList = new ArrayList<>();
        for (String s : list) {
            if (s.startsWith("张") && s.length() == 3){
                newList.add(s);
            }
        }
        System.out.println("newList = " + newList);

        List<String> newList1 = list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("张") && s.length() == 3;
            }
        }).collect(Collectors.toList());
        System.out.println("newList1 = " + newList1);

        List<String> newList2 = list.stream().filter(s -> s.startsWith("张") && s.length() == 3).collect(Collectors.toList());
        System.out.println("newList2 = " + newList2);


    }
}
